<template>
  <div class="category-percent">
    <div class="category-percent-content">
      <div class="category-percent-content-title">类别占比</div>
      <div class="category-percent-content-echarts">
        <screen-chart @initCb="initChart"></screen-chart>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
import { getPercentChartOption } from './option'
import { getSecurityTotalPer } from 'api/situationAwareness/securityPeople/securityPeople'
@Component({
  name: 'category-percent'
})
export default class CategoryPercent extends Vue {
  private percentChart: any = null

  private percentList: any = [
    // {
    //   name: 'BRT安保',
    //   value: 1678
    // },
    // {
    //   name: '站务人员',
    //   value: 1988
    // },
    // {
    //   name: '兼职保安',
    //   value: 1888
    // },
    // {
    //   name: '售票员',
    //   value: 2788
    // },
    // {
    //   name: '驾驶员',
    //   value: 2888
    // },
    // {
    //   name: '志愿者',
    //   value: 2888
    // }
  ]
  created() {
    this.getSecurityTotalPer()
  }

  private initChart(chart: any): void {
    chart.clear()
    this.percentChart = chart
  }

  async getSecurityTotalPer() {
    const params = {
      dzcode: ''
    }
    try {
      const res: any = await getSecurityTotalPer(params)
      console.log('分类统计', res)
      res.data.typeList.forEach((item: any) => {
        this.percentList.push({
          name: item.typeName,
          value: item.typeTotal - 0
        })
      })
      setTimeout(() => {
        this.percentChart.setOption(
          getPercentChartOption({
            data: this.percentList
          })
        )
      }, 300)
    } catch (error) {}
  }
}
</script>

<style lang="scss" scoped>
.category-percent {
  box-sizing: border-box;
  width: 100%;
  // height: 40.2%;
  height: 40%;
  .category-percent-content {
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    &-title {
      width: 100%;
      height: 30px;
      line-height: 30px;
      font-size: 18px;
      font-family: 'PingFang Regular';
      font-weight: 500;
      color: #ffffff;
      position: relative;
      padding-left: 33px;
      text-align: left;
    }
    &-title::after {
      content: '';
      display: block;
      width: 10px;
      height: 10px;
      border-radius: 50%;
      background: #23fffc;
      position: absolute;
      left: 18px;
      top: 10px;
    }
    &-echarts {
      width: 100%;
      height: calc(100% - 30px);
    }
  }
}
</style>
